
<%@ page import="pc.system.*,wstrader.*,wstrader.task.*" %>

<%
    Users user = Trader.getUser(request.getParameter("uid"));
	
	if (user == null || !user.Authenticated()) {
		response.sendRedirect("logon.jsp");	
		return;
	}
	
	wstrader.task.admin.Account task = user.admin.account;
	((Tasks)task.getOwner()).clearFocus();
	task.setFocus(true);

%>

<%@include file="../header.jsp"%>

<%
	task.doTask();			
%>

<link href="style.css" rel="stylesheet" type="text/css">

<script language="javascript">

function doCheckAll(cbx)
{
	var level = cbx.name.substring(4,5);
	var perm  = cbx.checked ? parseInt(cbx.value) : 0;;
	setValue("level",level);
	setValue("permission",perm);
	doTask(3);
}

function doCheck(cbx,menu)
{
	var perm  = cbx.checked ? parseInt(cbx.value) : 0;
	var type  = cbx.name.substring(0,4);
	var level = cbx.name.substring(4,5);
	var row   = cbx.name.substring(6);
	
	//alert(type);
	
	if (type == "full") {
		var o = getObj("read" + level + "_" + row);
		o.disabled = cbx.checked;
		o.checked  = cbx.checked;
	}
	setValue("level",level);
	//setValue("menu",menu);
	setValue("permission",perm);
	//alert(perm);
	setValue("menu" + level,menu);
	doTask(2);
}

function doSelect(level,menu)
{
	setValue("menu" + level,menu);
	doPost();
}

function newUser()
{
	var text = "New User";
	var idx = addNewListItem(getObj("user_id"),text);
	setValue("user_name",text);
	setValue("full_name","");
	setSelected("company_id",0);
	setValue("max_logon",1);
	setFocus("user_name");
	getObj("user_name").select();
}

function delUser()
{
	if (parseInt(getValue("user_id")) <= 0) return;
	if (!confirm("Are you sure to delete user '" + getSelectedText("user_id") + "' ?")) return;
	doTask(4);
}

function saveUser()
{
	var user_id = parseInt(getValue("user_id"));
	var pw = getValue("password");
	var rw = getValue("re_password");
	if (user_id <= 0 && pw == "") {
		alert("The password can not be blank.");
		return;
	}
	if (pw != rw) {
		alert("The password was not correctly confirmed.");
		return;
	}
	doTask(1);
}
</script>

<form method="POST" name="formMain" action="" onSubmit="">				  
    <table width="100%" border="0" class="style2">
      <tr bgcolor="#CCCCCC" style="font-weight:bold">
        <td align="center" valign="top">Accounts</td>
        <td height="21" align="center" valign="top">Detail</td>
      </tr>
      <tr>
        <td width="12%" valign="top">
		  <select name="user_id" size=15 class="style2" id="user_id" style="width:100%;" onChange="doPost()">
          <%task.getResponse().setOption(task.getMasterList("user_master","user_name"));%>
          <%task.getResponse().setSelected("user_id",task.user_id);%>
          </select><br><a href="javascript:newUser()"><img src="images/new.gif" border="0"></a>
          <a href="javascript:delUser()"><img src="images/delete.gif" width="15" height="15" border="0"></a> </td>
        <td width="88%" align="center" valign="top"><table width="100%"  border="0" cellpadding="0" cellspacing="0" class="style1">
          <tr align="center" bgcolor="#DDDDDD">
            <td width="30%">User Information </td>
            <td width="70%">Access Rights (R : Read Only, F : Full Control) </td>
          </tr>
		  <tr>
		  	<td><table width="100%"  border="0" class="style2">
              <tr>
                <td width="34%" align="right">User name</td>
                <td width="66%"><input name="user_name" type="text" id="user_name" class="style2" style="width:100%; text-align:left" tabindex="10" value="<%=task.user_ref.getString("user_name")%>"></td>
              </tr>
              <tr>
                <td align="right">Password</td>
                <td><input name="password" type="password" id="password" class="style2" style="width:100%; text-align:left" tabindex="10" value=""></td>
              </tr>
              <tr>
                <td align="right">Confirm password</td>
                <td><input name="re_password" type="password" id="re_password" class="style2" style="width:100%; text-align:left" tabindex="10" value=""></td>
              </tr>
              <tr>
                <td align="right">Full name</td>
                <td><input name="full_name" type="text" id="full_name" class="style2" style="width:100%; text-align:left" tabindex="10" value="<%=task.user_ref.getString("full_name")%>"></td>
              </tr>
              <tr>
                <td align="right">Company</td>
                <td><select name="company_id" id="company_id" onChange="" size=1 style="font-family:Arial; font-size:12px; width:100%;">
                  <option value="0" selected></option>
                  <%task.getResponse().setOption(task.getCompanyList("client"));%>
                  <%task.getResponse().setSelected("company_id",task.user_ref.getIntValue("company_id"));%>
                </select></td>
              </tr>
              <tr>
                <td align="right">Max logon</td>
                <td><input name="max_logon" type="text" id="max_logon" class="style2" style="width:40px; text-align:right" tabindex="10" value="<%=task.user_ref.getIntValue("max_logon")%>"></td>
              </tr>
            </table></td>
		  	<td valign="top"><table width="100%"  border="1" align="center" cellpadding="0" cellspacing="0" class="style2">
			  <tr>
			    <td width="33%" valign="top"><table width="100%"  border="0" class="style2">
				  <tr bgcolor="#CCFFFF" class="style1" align="center">
				    <td width="13%">R</td>
				    <td width="13%">F</td>
				    <td width="74%">Access</td>
				    </tr>
<%
	for (int i = 0; i < user.getChildSize() ; i++) { 
		Tasks ts = (Tasks)(user.getTask(i));
		String menu = ts.getName();
		String name = ts.getName().substring(0,1).toUpperCase() + ts.getName().substring(1).toLowerCase();
		int perm = task.getPermission(menu,1);
%>
                  <tr id="<%=menu%>" style="z-index:1">
                    <td><input type="checkbox" name="read1_<%=i%>" id="read1_<%=i%>" value="1" onClick="doCheck(this,'<%=menu%>')"; <%=(perm&1)==1?"checked":""%> <%=(perm&3)==3?"disabled":""%>></td>
                    <td><input type="checkbox" name="full1_<%=i%>" id="full1_<%=i%>" value="3" onClick="doCheck(this,'<%=menu%>')"; <%=(perm&3)==3?"checked":""%> ></td>
                    <td><a href="javascript:doSelect(1,'<%=menu%>');" style="color:#000000 "><%=name%></a></td>
                  </tr>
<%
	}
%>				  
                </table></td>
			    <td width="33%" valign="top"><table width="100%"  border="0" class="style2">
				  <tr bgcolor="#CCFFFF" class="style1" align="center">
                    <td width="13%">R</td>
                    <td width="13%">F</td>
                    <td width="74%">Access</td>
                  </tr>
<%
	Tasks  ta1 = task.getTask((Tasks)user,task.getRequest().getStringValue("menu1"));
	for (int i = 0; (ta1 != null) && (i < ta1.getChildSize()) ; i++) {
		Tasks ts = (Tasks)(ta1.getTask(i));
		String menu = ts.getName();
		int perm = task.getPermission(menu,2);		
		String name = ts.getName();
		if (name.equals("wn")) name = "Weight Note";
		if (name.equals("wr")) name = "Whse Receipt";
		if (name.equals("wc")) name = "Weight Cert.";
		name = name.substring(0,1).toUpperCase() + name.substring(1);
%>
                  <tr id="<%=menu%>" style="z-index:2">
                    <td><input type="checkbox" name="read2_<%=i%>" id="read2_<%=i%>" value="1" onClick="doCheck(this,'<%=menu%>')"; <%=(perm&1)==1?"checked":""%> <%=(perm&3)==3?"disabled":""%>></td>
                    <td><input type="checkbox" name="full2_<%=i%>" id="full2_<%=i%>" value="3" onClick="doCheck(this,'<%=menu%>')"; <%=(perm&3)==3?"checked":""%>></td>
					<td><a href="javascript:doSelect(2,'<%=menu%>');" style="color:#000000 "><%=name%></a></td>
                  </tr>
<%
	}
%>				  
                </table></td>
				<td width="34%" valign="top"><table width="100%"  border="0" class="style2">
				  <tr bgcolor="#CCFFFF" class="style1" align="center">
                    <td width="13%">R</td>
                    <td width="13%">F</td>
                    <td width="74%">Access</td>
                  </tr>
<%
	Tasks  ta2 = task.getTask(ta1,task.getRequest().getStringValue("menu2"));
	for (int i = 0; (ta2 != null) && (i < ta2.getChildSize()) ; i++) {
		Tasks ts = (Tasks)(ta2.getTask(i));
		String menu = ts.getName();
		int perm = task.getPermission(menu,3);		
		String name = ts.getName();
		if (name.equals("do")) name = "Delivery Order";
		if (name.equals("di")) name = "Delivery Instruction";
		if (name.equals("po")) name = "Processing Order";
		if (name.equals("yi")) name = "Yield Instruction";
		if (name.equals("eo")) name = "Export Order";
		if (name.equals("ei")) name = "Export Instruction";
		if (name.equals("si")) name = "Shipping Instruction";
		name = name.substring(0,1).toUpperCase() + name.substring(1);
%>
                  <tr id="<%=menu%>" style="z-index:3">
                    <td><input type="checkbox" name="read3_<%=i%>" id="read3_<%=i%>" value="1" onClick="doCheck(this,'<%=menu%>')"; <%=(perm&1)==1?"checked":""%> <%=(perm&3)==3?"disabled":""%>></td>
                    <td><input type="checkbox" name="full3_<%=i%>" id="full3_<%=i%>" value="3" onClick="doCheck(this,'<%=menu%>')"; <%=(perm&3)==3?"checked":""%>></td>
					<td><a href="javascript:doSelect(3,'<%=menu%>');" style="color:#000000 "><%=name%></a></td>
                  </tr>
                  <%
	}
%>
                </table></td>
			  </tr>
            </table>
	  	    </td>
		  </tr>
		  <tr>
		  	<td align="left"><a href="javascript:saveUser()"><img src="images/update.gif" width="15" height="15" border="0"></a></td>
		  	<td align="left">&nbsp;</td>
		  </tr>
        </table></td>
      </tr>
    </table>	
	<input type="hidden" name="uid"     id="uid"     value="<%=user.getuid()%>">
	<input type="hidden" name="task_id" id="task_id" value="0">
	<input type="hidden" name="level"   id="level"   value="0">
	<input type="hidden" name="permission" id="permission" value="0">
	
	<input type="hidden" name="menu1"   id="menu1"   value="<%=task.getRequest().getStringValue("menu1")%>">
	<input type="hidden" name="menu2"   id="menu2"   value="<%=task.getRequest().getStringValue("menu2")%>">
	<input type="hidden" name="menu3"   id="menu3"   value="<%=task.getRequest().getStringValue("menu3")%>">
</form>

<script language="javascript">
	var o = getObj("<%=task.getRequest().getStringValue("menu1")%>");
	if (o != null && o.style.zIndex == 1) o.bgColor ="#E7E5C4";	
	var o = getObj("<%=task.getRequest().getStringValue("menu2")%>");
	if (o != null && o.style.zIndex == 2) o.bgColor ="#E7E5C4";
	var o = getObj("<%=task.getRequest().getStringValue("menu3")%>");
	if (o != null && o.style.zIndex == 3) o.bgColor ="#E7E5C4";
</script>

<%@include file="../footer.jsp"%>

